<?php
$this->headLink()->appendStylesheet($this->baseUrl() . '/public/styles/datepicker/jquery.datepick.css');
$this->headScript()->prependFile($this->baseUrl() . '/public/scripts/datepicker/jquery.datepick.js');
?>
<script language="javascript">
    $(document).ready(function() {
        $('#data_job').dataTable( {
            "bJQueryUI": true,
            "bPaginate": false,
            "sScrollY": "250px",
            "bScrollCollapse": true,
            //"sPaginationType": "full_numbers",
            "oLanguage": {
                "sLengthMenu": "Mostrar _MENU_ Ordenes por pagina",
                "sZeroRecords": "Ninguna orden encontrada :(",
                "sInfo": "Mostrando _START_ a _END_ de _TOTAL_ Ordenes",
                "sInfoEmpty": "Mostrando 0 a 0 de 0 Ordenes",
                "sInfoFiltered": "(Filtrando de _MAX_ Ordenes)"
            }
        } );
        
        $('#data_job_finish').dataTable( {
            "bJQueryUI": true,
            "bPaginate": false,
            "sScrollY": "250px",
            "bScrollCollapse": true,
            //"sPaginationType": "full_numbers",
            "oLanguage": {
                "sLengthMenu": "Mostrar _MENU_ Ordenes por pagina",
                "sZeroRecords": "Ninguna orden encontrada :(",
                "sInfo": "Mostrando _START_ a _END_ de _TOTAL_ Ordenes",
                "sInfoEmpty": "Mostrando 0 a 0 de 0 Ordenes",
                "sInfoFiltered": "(Filtrando de _MAX_ Ordenes)"
            }
        } );
    } );
</script>
<style>
    label.error {
        display: none;
        padding: 0;
        margin-left: 5px;
    }
</style>
<?php
$status = array('Pendiente', 'En Progreso', 'Pendiente con cliente', 'Cambios', 'Más Información', 'Aprobado', 'Entregado');
?>
<article class="module width_full">
    <header><h3>Reportes de Trabajos</h3></header>
    <div class="module_content">
        <div style="display: none;">
            <img id="calImg" src="<?php echo $this->baseUrl() . '/public/img/calendar-blue.gif' ?>" alt="Popup" class="trigger">
        </div>
        <h3>Pendientes, En progreso, Cambios</h3>
        <div>
            <form method="post" id="formreport" name="formreport" action="<?php echo $this->url(); ?>">
                <table>
                    <tr>
                        <td style="width: 265px">
                            <span>Desde</span>
                            <input type="text" id="from_date" name="from_date" style="width: 200px;"/>
                        </td>
                        <td style="width: 265px">
                            <span>Hasta</span>
                            <input type="text" id="to_date" name="to_date" style="width: 200px;"/>
                        </td>
                        <td style="width: 150px">
                            <select id="departament" name="departament">
                                <option value="0">Todas Agencias</option>
                                <option value="37">Athos</option>
                                <option value="40">Velcro</option>
                                <option value="41">Raza</option>
                            </select>
                        </td>
                        <td style="width: 150px">
                            <select id="status" name="status">
                                <option value="9">--Todos los estados--</option>
                                <option value="0">Pendientes</option>
                                <option value="1">En Progreso</option>
                                <option value="3">Cambios</option>
                            </select>
                        </td>
                        <td>
                            <input type="submit" value="Generar Reporte"/>
                        </td>
                    </tr>
                </table>
            </form>
            <br/>
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="data_job" width="100%">
                <thead>
                    <tr>
                        <th>Agencia</th>
                        <th>Orden</th>
                        <th>Campa&ncaron;a</th>
                        <th>Trabajo</th>
                        <th>Fecha de entrada</th>
                        <th>Fecha de entrega</th>
                        <th>Usuarios</th>
                        <th>Estado</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $tareaUser = new Tarea_Model_DbTable_TareaUser(); ?>
                    <?php foreach ($this->resultJob as $value) : ?>
                        <tr>
                            <td><?php echo $value['agency']; ?></td>
                            <td><?php echo $value['code']; ?></td>
                            <td><?php echo $value['campania']; ?></td>
                            <td><?php echo $value['job']; ?></td>
                            <td><?php echo $value['create_date'] ?></td>
                            <td><?php echo $value['end_date']; ?></td>
                            <td><?php echo $value['users']; ?></td>
                            <td><?php echo $status[$value['status']]; ?></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            <br/>
            <br/>

            <h3>PENDIENTES EN CLIENTES, ENTREGADOS, APROBADOS</h3>
            <table cellpadding="0" cellspacing="0" border="0" class="display" id="data_job_finish" width="100%">
                <thead>
                    <tr>
                        <th>Agencia</th>
                        <th>Orden</th>
                        <th>Campa&ncaron;a</th>
                        <th>Trabajo</th>
                        <th>Fecha de entrada</th>
                        <th>Fecha de entrega</th>
                        <th>Usuarios</th>
                        <th>Estado</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($this->resultJobFinish != null): ?>
                        <?php foreach ($this->resultJobFinish as $value) : ?>
                            <tr>
                                <td><?php echo $value['agency']; ?></td>
                                <td><?php echo $value['code']; ?></td>
                                <td><?php echo $value['campania']; ?></td>
                                <td><?php echo $value['job']; ?></td>
                                <td><?php echo $value['create_date'] ?></td>
                                <td><?php echo $value['end_date']; ?></td>
                                <td><?php echo $value['users']; ?></td>
                                <td><?php echo $status[$value['status']]; ?></td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <div id="chart_div" style="width:400px; height:300px;"></div>
        <div id="table_div" style="width:400px;"></div>
    </div>
</article>

<script>
    $(function() {
        $('#from_date, #to_date').datepick({
            showOnFocus: false, 
            showTrigger: '#calImg',
            dateFormat: 'dd-mm-yyyy'
        });
        
        $("#formreport").validate({
            rules: {
                from_date: "required",
                to_date: "required"
            },
            messages: {
                from_date: "",
                to_date: ""
            }
        });
    });
</script>